var _currentPageIndex = GetQueryString("page");
_currentPageIndex = _currentPageIndex == undefined || _currentPageIndex == "" ? 1 : parseInt(_currentPageIndex);

var _type = GetQueryString("type");
_type = _type == undefined || _type == "" ? "" : _type;
//取静态页参数////////////////
function GetQueryString(key) {
    var result = location.search.match(new RegExp("[\?\&]" + key + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return result[1];
}
$(function () {
    $("li.like").click(function () {
        var $this = $(this);
       $.getJSON("Index/Request/IndexAjaxHelper.ashx",
       {
           method: "AddWikiLikeCount",
           contentID:$(this).find("a").attr("data-id")
       },
       function (jsonData) {
           if (jsonData.isSuccess == "Y") {
               $this.find("a").text(jsonData.likeCount);
           }
       });
    });
    //获取文章访问次数和点赞数
    if ($("#bloginfo").length > 0) {
        $.getJSON("Index/Request/IndexAjaxHelper.ashx",
        {
            method: "GetContentCount",
            contentID: $("#hidCid").val()
        },
        function (jsonData) {
            if (jsonData.isSuccess == "Y") {
                $("li.view").text(jsonData.viewCount);
                $("li.like").find("a").text(jsonData.likeCount);
            }
        });
    }
    $("#blogtab li a").removeClass("current"); if (_type == "") $("#all").addClass("current"); else $("#" + _type).addClass("current");
    //if ($("#pager").length > 0) {
    //    $("#pager").zPager({
    //        current: parseInt($("#hidCurrentPage").val()),
    //        totalData: parseInt($("#hidTotalCount").val()),
    //        pageData: 10
    //    });
    //    $("#pager a").click(function () {
    //        _currentPageIndex = $(this).attr("page-id");
    //        var url = _currentPageIndex + ".html";
    //        $(this).attr('href', url);
    //    })
    //}
    //loadWikiDataList();
});
function loadWikiDataList() {
    $.getJSON("Index/Request/IndexAjaxHelper.ashx",
        {
            method: "GetWikiList",
            currentPageIndex: _currentPageIndex,
            pageSize: 20,
            type: _type
        },
        function (jsonData) {
            if (jsonData.isSuccess == "Y") {
                $("#pager").zPager({
                    current: _currentPageIndex,
                    totalData: jsonData.totalCount,
                    pageData: jsonData.pageSize
                });
                $("#pager a").click(function () {
                    _currentPageIndex = $(this).attr("page-id");
                    var url = "wiki.html?page=" + _currentPageIndex;
                    if (_type != "") {
                        url = url + "&type=" + _type;
                    }
                    $(this).attr('href', url);
                })
                if (jsonData.totalCount > 0) {
                    var $trTemplateRow = $("#blogTemplate")
                    $trTemplateRow.show();
                    if (jsonData.items != undefined) {
                        $.each(jsonData.items, function (i, objContent) {
                            var $row = $trTemplateRow.clone();
                            $row.find("h3>a").attr("href","wiki/"+objContent.contentID+".html").text(objContent.title);
                            $row.find("p.blogtext").html(objContent.content);
                            $row.find("li.author").text(objContent.createBy);
                            $row.find("li.timer").text(objContent.createTime);
                            $row.find("li.view").text(objContent.viewCount);
                            $row.find("li.like").text(objContent.likeCount);
                            $row.find("li.lmname>a").attr("href", "wiki.html?type="+objContent.contentType).text(objContent.contentTypeName);
                            $("#contentlist").before($row);
                        })
                    }
                    $trTemplateRow.hide();
                    //加载数据信息
                }
            }
        }
    );
}